
package org.robot.dao;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jsoup.helper.StringUtil;
import org.robot.pojo.Author;

public class AuthorDao extends BaseDao {
    private static Log log = LogFactory.getLog(AuthorDao.class);

    public static boolean addAuthor(Author author) {
        try {
            String email = author.getEmail();
            if (StringUtil.isBlank(email))
                return save("t_author_notemail", author) > 0;
            else {
                if (email.matches("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*")) {
                    author.setEmail(email.toLowerCase());
                    return save("t_author_email", author) > 0;
                } else
                    throw new RuntimeException("邮箱:" + email + "的格式不对 paperid:" + author.getPaperid());
            }
        } catch (Exception e) {
            log.error("保存失败：" + author.getPaperid(), e);
        }
        return false;
    }

    public static void main(String[] args) {
        // Author auth = new Author();
        // auth.setFullName("pengdazheng");
        // auth.setEmail("josoifjss@qq.com");
        // auth.setPaperid(45621382L);
        // auth.setTaskId(246L);
        // System.out.println(addAuthor(auth));
    }
}
